<template>
	<view>
    <!-- 搜索组件 -->
        <view class="search-box">
          <my-search @click="gotoSearch"></my-search>
        </view>
    <!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true" class="ani_Lunbo">
		  <swiper-item v-for="(item,index) in indexList"  :key="index">
		    <navigator class="swiper-item" :url="'/subpkg/goods_detrail/goods_detrail?goods_id=' + item.goods_id">
          <image class="ani_Image" :src="item.image_src" ></image>
        </navigator>
		  </swiper-item>
		</swiper>
    <!-- 商品栏区域 -->
    <view class="nav_list">
      <view class="nav_item" v-for="(item,index) in navarList" :key='index' @click="navClickitem(item)">
        <image :src="item.image_src" class="nav-img"></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <view class="floor_list">
      <view class="floor_item" v-for="(item,index) in floorList" :key="index">
         <image :src="item.floor_title.image_src" class="floor_title"></image>
         <view class="floor-img-box">
           <navigator class="left-img-box" :url="item.product_list[0].url">
             <image  mode="widthFix" :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}"></image>
           </navigator>
           <view class="right-img-box">
              <navigator :url="item.url" class="right-img-item" v-for="(item,index) in item.product_list" :key="index" v-if="index !== 0">
                  <image mode="widthFix"  :src="item.image_src" :style="{width:item.image_width + 'rpx'}"></image>
              </navigator>
           </view>
         </view>
      </view>
    </view>
	</view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge.js'

export default {
  // 将 badgeMix 混入到当前的页面中进行使用
  mixins: [badgeMix],
  // 省略其它代码...
		data() {
			return {
				indexList:[],
        navarList:[],
        floorList:[]
			};
		},
    onLoad(){
      this.getIndexList()
      this.getnavarList()
      this.floorItemIndex()
    },
    methods:{
     async getIndexList(){
        const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')

        if(res.meta.status !== 200){
        return uni.$showMsg()
        }
        this.indexList = res.message
    
      },
      async getnavarList(){
         const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
   
         if(res.meta.status !== 200){
         return uni.$showMsg()
         }
         this.navarList = res.message
       },
      async floorItemIndex(){
         const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')

         if(res.meta.status !== 200){
         return uni.$showMsg()
         }
         res.message.forEach(floor =>{
           floor.product_list.forEach(prod => {
             prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
           })
         })
         this.floorList = res.message
       },
       navClickitem(item){

         if(item.name === "分类"){
           uni.switchTab({
             url:'/pages/Cate/Cate'
           })
       }
       },
        gotoSearch() {
           uni.navigateTo({
           url: '/subpkg/search/search'
         })
       }
     }
   }
</script>

<style lang="scss">
.ani_Lunbo {
   height: 330rpx;
   .swiper-item,
  .ani_Image {
    width: 100%;
    height: 100%;
  }
}
.nav_list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}
.floor_title {
  height: 60rpx;
  width: 100%;

}
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.floor-img-box {
  display: flex;
  padding-left: 10rpx;
}
.search-box {
  position: sticky;
  top: 0;
  z-index: 999;
  }
</style>
